"use strict";
cc._RF.push(module, 'bcdfb/B9UdMhofbCPqxUKQ7', 'power');
// scripts/O1ModuleRes/control/power.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var gameEngine_1 = require("../../engines/gameEngine");
var gameConfig_1 = require("../../engines/configs/gameConfig");
var userInterface_1 = require("../../engines/services/userContent/userInterface");
var data_control_1 = require("../../engines/libs/data_control");
var UnLockPage_1 = require("../../Game/Page/UnLockPage");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var power = /** @class */ (function (_super) {
    __extends(power, _super);
    function power() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.lbPower = null;
        _this.lbResetPower = null;
        _this.InfinityPower = null;
        _this.m_MemberTimeKey = "user-membertime";
        return _this;
    }
    power.prototype.start = function () {
        this.onUpdateTimer();
        this.schedule(this.onUpdateTimer.bind(this), 1);
    };
    power.prototype.onUpdateTimer = function () {
        var currPower = gameEngine_1.default.getServices().userSrv.getPower();
        var maxPower = gameEngine_1.default.getServices().userSrv.getMaxPower();
        var resetTime = gameEngine_1.services().userSrv.getPowerResetTimer();
        resetTime = Math.max(0, resetTime);
        // console.info("currPower",currPower,maxPower)
        //体力已满
        if (currPower >= maxPower) {
            this.lbPower.string = "" + currPower;
            //
            this.lbResetPower.string = "";
        }
        else { //体力还有得恢复
            this.lbPower.string = currPower + "/" + maxPower;
            //
            this.lbResetPower.string = data_control_1.default.getTimeFormatClock(resetTime);
            //恢复
            gameEngine_1.services().userSrv.onPowerTimerReset();
        }
        //判断无限体力是否过期
        var dateNow = data_control_1.default.getCurrDateDayString();
        var dateOld = gameEngine_1.default.getServices().userSrv.getInfinityTime();
        if (dateOld) {
            if (dateOld != dateNow) //如果大于24小时
             {
                if (gameEngine_1.default.getServices().userSrv.getInfinityPower()) {
                    gameEngine_1.default.getServices().userSrv.setPower(gameConfig_1.default.MAX_POWER, false, true);
                }
                gameEngine_1.default.getServices().userSrv.setInfinity(0);
                // O1HD.getModules().uiControlModule.showInfinityPower(gameConfig.FIRST_PLAY_INFINITY_PROBABILITY, mainRoot.UIRoot);
            }
        }
        else //如果是第一次进入游戏
         {
            gameEngine_1.default.getServices().userSrv.setInfinity(0);
            // O1HD.getModules().uiControlModule.showInfinityPower(gameConfig.FIRST_PLAY_INFINITY_PROBABILITY, mainRoot.UIRoot);
        }
        var unlockLevelTime = gameEngine_1.default.getServices().userSrv.getLevelAllUnlockTime();
        if (Date.now() - unlockLevelTime > 60 * 60 * 24 * 1000) {
            gameEngine_1.default.getServices().userSrv.setLevelAllUnlockTime();
            gameEngine_1.default.getServices().userSrv.setLevelAllUnlockFlag(false);
            UnLockPage_1.default.unlockAllTime = 0;
            gameEngine_1.default.emit("refrashAll");
        }
    };
    power.prototype.onBtnAddPower = function () {
        gameEngine_1.default.getManagers().soundMgr.playSound('mainSound/anNiu').then();
        gameEngine_1.modules().uiControlModule.showUserPropGet(userInterface_1.REWARD_TYPE.POWER, gameConfig_1.default.ADD_ONCE_POWER);
        // modules().uiControlModule.showUserPropGet(REWARD_TYPE.POWER, gameConfig.ADD_ONCE_POWER, null, () => {
        //     O1HD.getModules().uiControlModule.showInfinityPower(gameConfig.CLICK_POWER_INFINITY_PROBABILITY, mainRoot.UIRoot);
        // });
    };
    power.prototype.update = function (dt) {
    };
    __decorate([
        property(cc.Label)
    ], power.prototype, "lbPower", void 0);
    __decorate([
        property(cc.Label)
    ], power.prototype, "lbResetPower", void 0);
    __decorate([
        property(cc.Prefab)
    ], power.prototype, "InfinityPower", void 0);
    power = __decorate([
        ccclass
    ], power);
    return power;
}(cc.Component));
exports.default = power;

cc._RF.pop();